function doSuccess(res){
    if(res==null){
    	alert('出错了，请刷新页面重新尝试!');
		return;
    }
    if(typeof res.data.loginUrl!='undefined' && res.data.loginUrl!=''){
    	top.location.href	= res.data.loginUrl;
    }
    clearErrors('span', 'error_info');
    var l		= 0;
    if(typeof res.data.error_messages!='undefined'){
    	for(var name in res.data.error_messages){
    		for(var msgname in res.data.error_messages[name]){
    			setTextMsg(name+"_info",res.data.error_messages[name][msgname]);
    			break;
    		}
    		l++;
    	}
    }
    
    if(l==0){
    	if(typeof successFun!='undefined'){
    		successFun(res);
    	}
    }
}

function doError(res){
	alert(res.responseText);
}

function doingEdit(){

}

function setTextMsg(id,msg){
	document.getElementById(id).innerHTML	= msg;
}

function clearErrors(tagName,etype){
	var arr		= document.getElementsByTagName(tagName);
	for(var i=0,l = arr.length;i<l;i++){
		var	e	= arr[i];
		if(e.attributes['etype']!=undefined && e.attributes['etype'].nodeValue==etype){
			e.innerHTML	= '';
		}
	}
}

//轮播
function doSlide(id){
	id = id || 'J_Slide';
	var i=0;
	var _icon = $("#"+id+" .ks-switchable-nav li");
	var _list = $("#"+id+" .ks-switchable-content li");
	var _len = _icon.length;
	_icon.each(function(s){
		$(this).click(function(){
			_list.eq(s).fadeIn().siblings().hide();
			_icon.eq(s).addClass('ks-active').siblings().removeClass('ks-active');
			i=s;
		});
	});	
	_icon.eq(0).trigger("click");
	setInterval(function(){
		_icon.eq(i).trigger("click");
		i = ++i > _len ? 0 : i;
	},3000);
}


USER_ID = 0;
(function($){

	/*=====================会员BEGIN=====================*/
	$.Check_Login = function()
	{
		if(USER_ID == 0)
		{
			$.Show_Login_Form();
			return false;
		}
		else
			return true;
	}
	$.Show_Login_Form = function()
	{
		$.weeboxs.close();
		$.weeboxs.open("?module=User&action=LoginBox", {contentType:'ajax',draggable:false,showButton:false,title:LANG.login,width:600});
	}
	
	$.Show_Tooltip = function(msg,isErr)
	{
		var readyFun = function(weebox){
			var fun = function()
			{
				$.weeboxs.close();
			}
			$("#TOOLTIP_BOX").width(weebox.dc.get(0).scrollWidth + 100);
			setTimeout(fun,1500);
		};
		var c = 'lb_s';
		if(isErr)
			var c = 'lb_f';
		var html = '<div class="lb_tooltip"><a class="lb_close" href="javascript:;" onclick="$.weeboxs.close()"></a><div class="'+c+'">'+msg+'</div></div>';
		$.weeboxs.close();
		$.weeboxs.open(html, {boxid:'TOOLTIP_BOX',contentType:'text',draggable:false,showButton:false,showHeader:false,width:100,onready:readyFun});
	}
	//关注会员，uid 要关注的会员编号，ojb 点击对像，fun 处理函数
	$.User_Follow_Remove=function(uid,obj,fun)
	{
		if(!$.Check_Login())
			return false;

		var query = new Object();
		query.uid = uid;

		$.ajax({
			url: "?module=User&action=FollowRemove",
			type: "POST",
			data:query,
			dataType: "json",
			success: function(result){
				if(result.html != null && fun == null)
					$(obj).html(result.html);
				
				if(fun != null)
				{
					result.uid = uid;
					fun.call(this,obj,result);
				}
			}
		});
	}
//关注会员，uid 要关注的会员编号，ojb 点击对像，fun 处理函数
	$.User_Follow=function(uid,obj,fun)
	{
		if(!$.Check_Login())
			return false;

		var query = new Object();
		query.uid = uid;

		$.ajax({
			url: "?module=User&action=FollowAdd",
			type: "POST",
			data:query,
			dataType: "json",
			success: function(result){
				if(result.html != null && fun == null)
					$(obj).html(result.html);
				
				if(fun != null)
				{
					result.uid = uid;
					fun.call(this,obj,result);
				}
			}
		});
	}
	//删除粉丝，uid 要删除的会员编号，fun 处理函数
	$.Remove_Fans=function(uid,obj,fun)
	{
		if(!$.Check_Login())
			return false;

		var query = new Object();
		query.uid = uid;

		$.ajax({
			url: "?module=Fans&action=Del",
			type: "POST",
			data:query,
			dataType: "json",
			success: function(result){
				if(fun != null)
					fun.call(this,obj,result);
			}
		});
	}

	/*=====================会员END  =====================*/
	
	/*=====================喜欢分享BEGIN=====================*/
	//喜欢分享
	$.Fav_Share = function(share_id,obj)
	{
		if(!$.Check_Login())
			return false;

		var query = new Object();
		query.share_id = share_id;
		
		$.ajax({
			url: "?module=Share&action=Fav",
			type: "POST",
			data:query,
			dataType: "json",
			success:function(result){
				$.Close_Fav_Box();
				var mg = '<div class="fav_fanwe" id="fav_fanwe"></div>';
				$("body").append(mg);
				var left = $(obj).offset().left;
				var top = $(obj).offset().top;

				$("#fav_fanwe").css({"opacity":0,"left":left,"top":top-10});
				$("#fav_fanwe").animate({top:top-25,opacity:1},"fast",'swing',function(){
					if(result.code == 105)
						var box = "<div class='fav_tip' id='fav_tip'><div class='ffail'>"+ LANG.zhiji +"</div></div>";
					if(result.code == 100)
						var box = "<div class='fav_tip' id='fav_tip'><div class='ffail'><span>"+ LANG.fav_share_yi +"</span><a onclick='$.Remove_Fav_Share("+share_id+");' href='javascript:;'>"+ LANG.remove +"</a></div></div>";
					if(result.code == 101)
						var box = "<div class='fav_tip' id='fav_tip'><div class='ffail'>"+ LANG.zhiji +"</div></div>";
					if(result.code == 102)
					{
						var box = "<div class='fav_tip' id='fav_tip'><div class='fok'><a onclick='$.Pop_Share_Comment("+share_id+");' href='javascript:;'>"+ LANG.fav_comment +"</a></div></div>";
						$("#SHARE_FAV_COUNT_"+share_id).html(result.data.share.collect_num);
					}
					$("body").append(box);
					$("#fav_tip").css({"left":left-30,"top":top-90}).fadeIn();
					$("#fav_fanwe").hover(function(){
						clearTimeout(VTUI.Fav_Timer);
					},function(){
						var fun = function(){
							$.Close_Fav_Box();
						};
						VTUI.Fav_Timer = setTimeout(fun,3000);
					});

					$("#fav_tip").hover(function(){
						clearTimeout(VTUI.Fav_Timer);
					},function(){
						var fun = function(){
							$.Close_Fav_Box();
						};
						VTUI.Fav_Timer = setTimeout(fun,3000);
					});
				});
			}
		});
	}

	$.Remove_Fav_Share = function(share_id)
	{
		if(!$.Check_Login())
			return false;

		var query = new Object();
		query.share_id = share_id;
		$.ajax({
			url: "?module=Share&action=FavDel",
			type: "POST",
			data:query,
			dataType: "json",
			success: function(result){
				if(result.code == 100)
				{
					$("#SHARE_FAV_COUNT_"+share_id).html(result.data.share.collect_num);
					$.Close_Fav_Box();
				}
			}
		});
	}

	$.Close_Fav_Box = function()
	{
		clearTimeout(VTUI.Fav_Timer);
		$("#fav_fanwe").remove();
		$("#fav_tip").remove();
	}
	/*=====================喜欢分享END  =====================*/

	/*=====================评论分享BEGIN=====================*/
	$.Pop_Share_Comment = function(share_id)
	{
		$.Close_Fav_Box();
		$.weeboxs.close();

		if(!$.Check_Login())
			return false;

		$.weeboxs.open("?module=Share&action=Comment&share_id="+share_id, {boxid:'COMMENT_BOX',contentType:'ajax',draggable:false,showButton:false,title:LANG.comment_share,width:480});
	}
	$.Add_Share_Comment = function(obj,parentID)
	{
		$.weeboxs.close();
		if(!$.Check_Login())
			return false;
		
		var form = $(obj).parents("form");
		var formobj = form.get(0);

		if($.trim(formobj.content.value)=='')
		{
			alert(LANG.comment_content_require);
			formobj.content.focus();
			return false;
		}
		var query = form.serialize();
		if (parentID){
			var _obj = $(obj);
			_obj.attr('data-val', _obj.val());
			_obj.val('').addClass('pub_loading').attr("disabled",true);
		}
		$.ajax({
			url: "?module=Share&action=CommentAdd",
			type: "POST",
			cache:false,
			data:query,
			dataType: "json",
			success: function(result){
				if (parentID){
					_obj.val($(obj).attr('data-val')).removeClass('pub_loading').attr("disabled",false);
				}
				if(result.code == 100)
				{
					formobj.reset();
					if($(parentID).length > 0 && VTUI.ShareCommentHtml)
					{
						var item = $(VTUI.ShareCommentHtml(result.data)).css({"display":"none"});
						$(parentID).prepend(item);
						item.slideDown("slow");
					}
					$.weeboxs.close();
				}
				else
				{
					alert(result.message);
				}
			}
		});
	}
	
	
	/*=====================评论分享END  =====================*/
	/*=====================分享发布BEGIN=====================*/
		//分享重置
	/*=====================分享发布BEGIN=====================*/
	//发布时删除分享图片的处理
	$.Pub_Share_Img_Remove = function(obj)
	{
		var form = $(obj).parents("form");
		var oparent = $(obj).parent().parent();
		var rparent = oparent.parent();
		oparent.remove();
		$.Pub_Share_Tags(form);
		if(typeof(PicItemCheckFun) == "function")
			PicItemCheckFun();
	}

	//发布时根据分享图片确定是否显示标签输入
	$.Pub_Share_Tags = function(form)
	{
		if($('.pub_img li',form).length == 0)
			$('.PUB_SHARE_TAG_BOX',form).hide();
		else
		{
			$('.PUB_SHARE_TAG_BOX',form).show();
			var tags = new Array();
			$(".GOODS_ITEM_TAG",form).each(function(){
				tags.push(this.value.split(' '));
			});
			if(tags.length > 0)
			{
				var activeTags = $(".PUB_SHARE_TAG",form).val();
				if(activeTags != '')
				{
					activeTags = activeTags.replace('　',' ');
					activeTags = activeTags.replace(/ +/g,' ');
					activeTags = ' ' + $.trim(activeTags) + ' ';
				}

				var html = '';
				var tagCount = SETTING.share_tag_count;
				var tempObj = new Object();
				var tag = '';
				for(var i = 0; i < tagCount; i++)
				{
					for(var j=0; j < tags.length; j++)
					{
						if(tags[j].length > i)
						{
							tag = tags[j][i];
							if(tempObj[tag] == null)
							{
								tempObj[tag] = 1;
								if(activeTags.indexOf(' ' + tag + ' ') == -1)
									html += '<li>'+ tag +'</li>';
								else
									html += '<li class="active">'+ tag +'</li>';
							}
						}
					}
				}
				delete tempObj;
				$(".PUB_SHARE_TAG_BOX ul",form).html(html).show();
			}
			else
			{
				$(".PUB_SHARE_TAG_BOX ul",form).hide();
			}
		}
	}
	
	//分享重置
	$.Pub_Share_Reset = function(form)
	{
		form.reset();
		$('.PUB_IMG li',form).remove();
		$('.PUB_SHARE_TAG_BOX,.PUB_IMG',form).hide();
	}
	
	$.Share_Save = function(obj)
	{
		if(!$.Check_Login())
			return false;
        var form = $(obj).parents("form").get(0);
		var url = $.trim(form.hdShareUrl.value);
		var content = $.trim(form.content.value);
		if(content == '')
		{
			alert(LANG.share_content_require);
			return;
		}
		var butTxt = $(obj).val();
		$(obj).val('').addClass('pub_loading').attr("disabled",true);
		$.ajax({
			url: url,
			type: "POST",
			data:$(form).serialize(),
			cache:false,
			dataType: "json",
			success:function(result){
				$(obj).val(butTxt).removeClass('pub_loading').attr("disabled",false);
				if(result.code == 200)
				{
					$.Pub_Share_Reset(form);
					if(VTUI.ShareHtml)
					{
						var share_item = $(VTUI.ShareHtml(result.data)).css({"display":"none"});
						$('#talk_list_box').prepend(share_item);
						share_item.slideDown("slow");
					}else{
						if (result.message)$.Show_Tooltip(result.message);
					}
				}
				else
				{
					if(result.error_msg)
						alert(result.error_msg);
					else
						alert(LANG.pub_share_tip1);
				}
			},
			error:function(){
				$(obj).val(butTxt).removeClass('pub_loading').attr("disabled",false);
				alert(LANG.pub_share_tip1);
			}
		});
    };
/*=====================分享发布END=====================*/
	
/*=====================说说发布START=====================*/
//显示weibo转发
$.Repost_Weibo = function(id)
{
	if(!$.Check_Login())
		return false;
	$.weeboxs.close();
	$.weeboxs.open("?module=User&action=WeiboRepost&id="+id, {boxid:'RELAY_BOX',contentType:'ajax',draggable:false,showButton:false,title:LANG.relay_share,width:480,isFull:true});
}

$.Add_Weibo_Repost = function(obj)
{
	$.weeboxs.close();
	if(!$.Check_Login())
		return false;
	
	var form = $(obj).parents("form");
	var formobj = form.get(0);

	if($.trim(formobj.content.value)=='')
	{
		alert(LANG.comment_content_require);
		formobj.content.focus();
		return false;
	}
	var query = form.serialize();
	$.ajax({
		url: "?module=User&action=WeiboRepostSave",
		type: "POST",
		cache:false,
		data:query,
		dataType: "json",
		success: function(result){
			if(result.code == 200)
			{
				formobj.reset();
				$.weeboxs.close();
				if (result.message)$.Show_Tooltip(result.message);
			}
			else
			{
				alert(result.message);
			}
		}
	});
}

$.Weibo_Save = function(obj)
{
	if(!$.Check_Login())
		return false;

    var form = $(obj).parents("form").get(0);
	var content = $.trim(form.content.value);
	if(content == '')
	{
		alert(LANG.share_content_require);
		return;
	}
	var butTxt = $(obj).val();
	$(obj).val('').addClass('pub_loading').attr("disabled",true);
	$.ajax({
		url: '?module=User&action=Weibo',
		type: "POST",
		data:$(form).serialize(),
		cache:false,
		dataType: "json",
		success:function(result){
			$(obj).val(butTxt).removeClass('pub_loading').attr("disabled",false);
			if(result.code == 200)
			{
				
				form.reset();
				if(VTUI.ShareHtml)
				{
					var share_item = $(VTUI.ShareHtml(result.data)).css({"display":"none"});
					$('#talk_list_box').prepend(share_item);
					share_item.slideDown("slow");
				}
			}
			else
			{
				if(result.error_msg)
					alert(result.error_msg);
				else
					alert(LANG.pub_share_tip1);
			}
		},
		error:function(){
			$(obj).val(butTxt).removeClass('pub_loading').attr("disabled",false);
			alert(LANG.pub_share_tip1);
		}
	});
};


$.Get_Weibo_Comment_List = function(obj)
{
	var parent = $(obj).parent();
	var cmtList = parent.siblings('.SHARE_COMMENT_LIST_BOX');
	if(cmtList.length > 0)
	{
		cmtList.remove();
		return false;
	}

	var query = new Object();
	query.id = $(obj).attr('data-id');

	$.ajax({
		url: "?module=User&action=WeiboComment",
		data:query,
		cache:false,
		type: "POST",
		success: function(html){
			parent.after(html);
			parent.siblings('.SHARE_COMMENT_LIST_BOX').show();
			$.Pub_Count_Bind($(".SHARE_COMMENT_LIST_BOX .PUB_TXT").get(0));
		}
	});
}

$.Add_Weibo_Comment = function(obj,parentID)
{
	$.weeboxs.close();
	if(!$.Check_Login())
		return false;
	
	var form = $(obj).parents("form");
	var formobj = form.get(0);

	if($.trim(formobj.content.value)=='')
	{
		alert(LANG.comment_content_require);
		formobj.content.focus();
		return false;
	}
	var query = form.serialize();
	if (parentID){
		var _obj = $(obj);
		_obj.attr('data-val', _obj.val());
		_obj.val('').addClass('pub_loading').attr("disabled",true);
	}
	$.ajax({
		url: "?module=User&action=WeiboCommentAdd",
		type: "POST",
		cache:false,
		data:query,
		dataType: "json",
		success: function(result){
			if (parentID){
				_obj.val($(obj).attr('data-val')).removeClass('pub_loading').attr("disabled",false);
			}
			if(result.code == 200)
			{
				formobj.reset();
				if($(parentID).length > 0 && VTUI.WeiboCommentHtml)
				{
					var item = $(VTUI.WeiboCommentHtml(result.data)).css({"display":"none"});
					$(parentID).prepend(item);
					item.slideDown("slow");
				}
				$.weeboxs.close();
			}
			else
			{
				alert(result.message);
			}
		}
	});
}

$.Del_Weibo_Comment = function(id){
	var query = 'id='+id;
	$.ajax({
		url: "?module=User&action=WeiboCommentDel",
		type: "POST",
		cache:false,
		data:query,
		dataType: "json",
		success: function(result){
			if(result.code == 200)
			{
				$('#WEIBO_COMMENT_'+id).slideToggle('slow',function(){$(this).remove();});
			}
			else
			{
				alert(result.message);
			}
		}
	});
}

$.Reply_Comment = function(obj)
{
	if(!$.Check_Login())
		return false;

	var userName = $(obj).attr('uname');
	var cid = $(obj).attr('cid');
	var form = $(obj).parents("form").get(0);
	form.content.value = "//@"+ userName +":" + form.content.value;
	form.parent_id.value = cid;
}
/*=====================说说发布END=====================*/
	
/*=====================宝贝BEGIN=====================*/
	//显示商品添加窗口
	$.Goods_Add = function(obj)
	{
		if(!$.Check_Login())
			return;

		var form = $(obj).parents("form");
		if($.Get_Goods_Count(form) >= SETTING.share_goods_count)
		{
			alert(LANG.goods_collect_3.replace('%d',SETTING.share_goods_count));
			return;
		}

		$.weeboxs.close();
		var closeFun = function(){
			$.Goods_Collect_Clear();
		};
		var readyFun = function(weebox){
			VTUI.Goods_Collect_HTML = weebox.dc.html();
			$.Goods_Init(weebox);
		};
		if(VTUI.Goods_Collect_HTML == null)
			$.weeboxs.open("?module=Share&action=Goods",{boxid:'ADD_GOODS_BOX',contentType:'ajax',position:{refele:obj},draggable:false,modal:false,showButton:false,width:496,onclose:closeFun,onready:readyFun});
		else
			$.weeboxs.open(VTUI.Goods_Collect_HTML,{boxid:'ADD_GOODS_BOX',contentType:'text',position:{refele:obj},draggable:false,modal:false,showButton:false,width:496,onclose:closeFun,onready:readyFun});
	}

	//采集商品初始化
	$.Goods_Init = function(weebox)
	{
		$('.GOODS_COLLECT',weebox.dc).click(function(){
			$.Goods_Collect(weebox);
		});
	}

	//采集商品
	$.Goods_Collect = function(weebox)
	{
		var refele = weebox.options.position.refele;
		var form = $(refele).parents("form");
		var query = form.serialize();
		var url = $.trim($('.GOODS_URL',weebox.dc).val());

		if(url == '')
		{
			alert(LANG.goods_collect_5);
			return;
		}

		$('.PUB_LOADING',weebox.dc).show();
		$('.GOODS_BOX',weebox.dc).hide();

		$.Goods_Collect_Clear();
		VTUI.Goods_Collect_Handler = new Object();
		VTUI.Goods_Collect_Handler.fun = function(result){
			$.Goods_Collect_Result(result,weebox,form);
		};
		
		query += "&url="+escape(url)+"&image_server="+VTUI.UPLOAD_IMAGE_SERVER;

		VTUI.Goods_Collect_Handler.ajax = $.ajax({
			url: "?module=Share&action=CollectGoods",
			type: "POST",
			data:query,
			cache:false,
			dataType: "json",
			success:function(result){
				if(result.status == 1)
					VTUI.UPLOAD_IMAGE_SERVER = result.image_server;

				if(VTUI.Goods_Collect_Handler.fun != null)
					VTUI.Goods_Collect_Handler.fun(result);
			},
			error:function(){
				alert(LANG.goods_collect_4);
				$.Goods_Close();
			}
		});
	}

	//处理采集返回的结果
	$.Goods_Collect_Result = function(result,weebox,form)
	{
		VTUI.Goods_Collect_Handler.fun = null;
		VTUI.Goods_Collect_Handler.ajax = null;
		VTUI.Goods_Collect_Handler = null;

		if(result.code == 1)
		{
			$('.pub_img',form).show().append(result.data.item);
			weebox.setContent(result.data.html,true);
			$.Pub_Share_Tags(form);
			weebox.dc.ready(function(){
				if($('.TIME_OUT_CLOSE[time]',weebox.dc).length > 0)
					$.Goods_Close_Timer(weebox);
			});
			return;
		}
		else if(result.code == 0)
		{
			alert(LANG.goods_collect_4);
		}
		else if(result.code == -1)
		{
			alert(LANG.goods_collect_2);
		}
		else if(result.code == -2)
		{
			alert(LANG.goods_collect_3.replace('%d',SETTING.share_goods_count));
		}
		else if(result.code == -3)
		{
			alert(LANG.goods_collect_6);
		}
		$.Goods_Close();
	}

	//timer关闭商品添加窗口
	$.Goods_Close_Timer = function(weebox)
	{
		var timeout = $('.TIME_OUT_CLOSE',weebox.dc);
		var time = parseInt(timeout.attr("time"));
		if(isNaN(time) || time <= 0)
		{
			VTUI.Goods_Collect_Close_Timer = null;
			delete VTUI.Goods_Collect_Close_Timer;
			$.Goods_Close();
			return;
		}
		timeout.val(LANG.goods_collect_1.replace('%d',time));
		time--;
		timeout.attr({"time":time});

		var timerFun = function(){
			$.Goods_Close_Timer(weebox);
		};
		VTUI.Goods_Collect_Close_Timer = setTimeout(timerFun,1000);
	}

	//关闭商品添加窗口
	$.Goods_Close = function()
	{
		$.Goods_Collect_Clear();
		$.weeboxs.close();
	}

	//清除商品的采集
	$.Goods_Collect_Clear = function()
	{
		if(VTUI.Goods_Collect_Handler != null)
		{
			VTUI.Goods_Collect_Handler.fun = null;
			VTUI.Goods_Collect_Handler.ajax.abort();
			VTUI.Goods_Collect_Handler.ajax = null;
			VTUI.Goods_Collect_Handler = null;
		}
	}

	//获取已发布商品的数量
	$.Get_Goods_Count = function(form)
	{
		return $('.pub_img .PUB_SHARTE_GOODS',form).length;
	}
	/*=====================宝贝END  =====================*/

/*=====================表情BEGIN=====================*/
	//显示表现窗口
	$.Show_Expression = function(obj,height)
	{
		var readyFun = function(weebox){
			VTUI.Expression_HTML = weebox.dc.html();
			$.Expression_Init(weebox);
		};
		if(VTUI.Expression_HTML == null)
			$.weeboxs.open("?module=Share&action=Expression",{boxid:'EXPRESSION_BOX',contentType:'ajax',position:{refele:obj},draggable:false,modal:false,showButton:false,showHeader:false,width:496,onready:readyFun,addtop:height});
		else
			$.weeboxs.open(VTUI.Expression_HTML,{boxid:'EXPRESSION_BOX',contentType:'text',position:{refele:obj},draggable:false,modal:false,showButton:false,showHeader:false,width:496,onready:readyFun,addtop:height});
	}

	//表情处理
	$.Expression_Init = function(weebox)
	{
		var refele = weebox.options.position.refele;
		var form = $(refele).parents("form");

		$("#expression_tabs li").click(function(){
			$("#expression_tabs li").removeClass("c");
			$(this).addClass("c");
			$.Get_Expression($(this).attr("f"),form);
		});

		$.Expression_Click(form);
	}

	//获取表情
	$.Get_Expression = function(type,form)
	{
		if(Expression_Items[type] != null)
		{
			$("#expression_items a").unbind();
			$("#expression_items").html(Expression_Items[type]);
			$.Expression_Click(form);
		}
	}

	//处理点击表情
	$.Expression_Click = function(form)
	{
		$("#expression_items a").bind("click",function(){
			var face = $.trim(this.getAttribute('rel'));
			if(face != '')
			{
				face = '['+ face +']';
				if($(".PUB_TXT",form).length == 0)
					return false;

				var txt = $(".PUB_TXT",form);
				var pos = parseInt(txt.attr("position"));
				var val = txt.val();

				if(txt.attr('length') != undefined)
				{
					var maxLength = parseInt(txt.attr('length'));
					if(val.length + face.length > maxLength)
						return false;
				}

				var begin = val.substr(0,pos);
				var end = val.substr(pos);
				txt.val(begin + face + end);
				txt.attr({"position":pos + face.length});
				$.Recount_Word(txt.get(0));
			}
		});
	}
	/*=====================表情END  =====================*/
	
	//字数统计
	$.Recount_Word = function(obj)
	{
		var form = obj.form;
		if(obj.getAttribute('length') == undefined)
			return false;

		var maxLength = obj.getAttribute('length');

		var cnt = $(obj).val();

		var length = cnt.length;
		if(length > maxLength)
		{
			cnt = cnt.substr(0,maxLength);
			$(obj).val(cnt);
			$(".WORD_COUNT",form).html(0);
		}
		else
		{
			var less = maxLength - length;
			$(".WORD_COUNT",form).html(less);
		}
	}
	
	//分享发布输入框绑定
	$.Pub_Count_Bind = function(obj)
	{
		var txt = $(obj);
		txt.attr({"position":txt.val().length});

		txt.bind('click', function(){
			txt.attr({"position":$(this).position()});
		});

		txt.bind('keyup', function(){
			txt.attr({"position":$(this).position()});
			if(this.getAttribute("cut") != 'false')
				$.Recount_Word(this);
		});

		if(txt.length > 0)
			$.Recount_Word(obj);
	}

	//获取光标位置
	$.fn.position = function(){
		var s,e,range,stored_range;
		if(this[0].selectionStart == undefined)
		{
			var selection=document.selection;
			if (this[0].tagName.toLowerCase() != "textarea")
			{
				var val = this.val();
				range = selection.createRange().duplicate();
				range.moveEnd("character", val.length);
				s = (range.text == "" ? val.length:val.lastIndexOf(range.text));
				range = selection.createRange().duplicate();
				range.moveStart("character", -val.length);
				e = range.text.length;
			}
			else
			{
				range = selection.createRange(),
				stored_range = range.duplicate();
				stored_range.moveToElementText(this[0]);
				stored_range.setEndPoint('EndToEnd', range);
				s = stored_range.text.length - range.text.length;
				e = s + range.text.length;
			}
		}
		else
		{
			s=this[0].selectionStart,
			e=this[0].selectionEnd;
		}
		var te=this[0].value.substring(s,e);
		return s;
	};


	
})(jQuery);


var userMenuTimeOut = null;
jQuery(function($){
    $(".my_shotcuts a.message").hover(function(){
		$("#notice_menu").show();
	},function(){
		var menuHide = function(){
			$("#notice_menu").hide();
		};
		userMenuTimeOut = setTimeout(menuHide,100);
	});

	$("#notice_menu").hover(function(){
		clearTimeout(userMenuTimeOut);
	},function(){
		$(this).hide();
	});

	$(".PUB_TXT[position]").each(function(){
		$.Pub_Count_Bind(this);
	});

	$("input[tooltip],textarea[tooltip]").each(function(){
		if($.trim(this.value) == '')
		{
			this.value = this.getAttribute('tooltip');
			$(this).addClass('tipcolor');
		}
	});

	$("input[tooltip],textarea[tooltip]").focus(function(){
		$(this).removeClass('tipcolor');
		var tooltip = this.getAttribute('tooltip');
		if(this.value == tooltip)
			this.value = '';
	}).blur(function(){
		$(this).removeClass('tipcolor');
		if($.trim(this.value) == '')
		{
			this.value = this.getAttribute('tooltip');
			$(this).addClass('tipcolor');
		}
	});
//
//	$('.SHOW_BIG_PIC').live('mousemove', function(){
//		$('.SHOW_BIG',this).show();
//	}).live('mouseout', function(){
//		$('.SHOW_BIG',this).hide();
//	});
//
//	$('.SHARE_MANAGE').live('mouseover', function(){
//		clearTimeout(VTUI.SHARE_MANAGE);
//		$(".SHARE_MANAGE_LIST_CLONE").remove();
//		var list = $(this).parent().siblings(".SHARE_MANAGE_LIST");
//		var clone = list.clone();
//		var left = $(this).offset().left + 10;
//		var top = $(this).offset().top + 20;
//		var height = $('li',list).length * 20 + 4;
//		$('body').append(clone);
//		clone.addClass('t_m_l SHARE_MANAGE_LIST_CLONE').css({"left":left,"top":top,"height":height}).slideDown(100);
//	}).live('mouseout', function(){
//		clearTimeout(VTUI.SHARE_MANAGE);
//		var fun = function(){
//			$(".SHARE_MANAGE_LIST_CLONE").hide();
//		}
//		VTUI.SHARE_MANAGE = setTimeout(fun,2000);
//	});
//
//	$(".SHARE_MANAGE_LIST_CLONE").live('mouseover', function(){
//		clearTimeout(VTUI.SHARE_MANAGE);
//		$(this).show();
//	}).live('mouseout', function(){
//		$(this).hide();
//	});
//
//	$(".PUB_SHARE_TAG_BOX li").live('click', function(){
//		var form = $(this).parents("form");
//		var tagInput = $('.PUB_SHARE_TAG',form);
//		var tagValue = tagInput.val();
//		tagValue = tagValue.replace('　',' ');
//		tagValue = tagValue.replace(/ +/g,' ');
//		tagValue = ' ' + $.trim(tagValue) + ' ';
//		if($(this).hasClass('active'))
//		{
//			tagValue = tagValue.replace(' ' + $(this).html() + ' ',' ');
//			$(this).removeClass('active');
//		}
//		else
//		{
//			tagValue += $(this).html();
//			$(this).addClass('active');
//		}
//
//		tagValue = $.trim(tagValue);
//		tagInput.val(tagValue);
//	});
//
	var backtop = $("#back2top");
	if(backtop.length > 0)
	{
		var body_width = 960;
		body_width = $.browser.msie && $.browser.version == "6.0" ? 950 : 953;
		backtop.css("left",Math.floor(($(window).width()-body_width)/2) + body_width + 5 + "px");
		$(window).scroll(function(){
			$(window).scrollTop()==0 ? backtop.fadeOut() : backtop.fadeIn()
		});
		$(window).resize(function(){
			var resize_width = Math.floor(($(window).width()-body_width)/2);
			if(resize_width > 10)
				backtop.css("left",resize_width + body_width + 5 + "px");
		});
	}
//	
//	$(".add_to_album_btn").each(function(){
//		$(this).parent().hover(function(){
//			$(".add_to_album_btn",this).show();
//		},function(){
//			$(".add_to_album_btn",this).hide();
//		});
//	});
	$('.WEIBO_COMMENT').click(function(){
		$.Get_Weibo_Comment_List(this);
	});
	$('.WEIBO_REPOST').click(function(){
		$.Repost_Weibo($(this).attr('data-id'));
	});
	$('.WEIBO_COMMENT_DEL').click(function(){
		$.Del_Weibo_Comment($(this).attr('data-id'));
	});
	
		
	$('.User_Follow').click(function(){
		$.User_Follow($(this).attr('data-id'));
	});
	$('.add_face_new').click(function(){
		$.Show_Expression(this,20);
	});
	
	$('.SHARE_FAV_A').click(function(){
		$.Fav_Share($(this).attr('data-shareid'), this);
	});
	
	$(".GUID").live('mouseover',function(){
		if(VTUI.GUID_DEFAULT_HTML == null)
			VTUI.GUID_DEFAULT_HTML = $("#USER_INFO_TIP").html();
		clearTimeout(VTUI.GUID_TIME_OUT);
		ClearUserTipAjax();
		var uid = parseInt(this.getAttribute('uid'));
		if(uid < 1)
			return;

		UserTipShow(this,VTUI.GUID_DEFAULT_HTML);
		var query = new Object();
		query.uid = uid;
		
		var thisobj = this;
		
		VTUI.User_Tip_Ajax = $.ajax({
			url: "?module=User&action=Tip",
			type: "POST",
			data:query,
			cache:false,
			dataType: "html",
			success:function(html){
				if(html != '')
				{
					UserTipShow(thisobj,html);
				}
				else
					$("#USER_INFO_TIP").hide();
				ClearUserTipAjax();
			},
			error:function(){
				$("#USER_INFO_TIP").hide();
				ClearUserTipAjax();
			}
		});
	}).live('mouseout',function(){
		var fun = function(){
			$("#USER_INFO_TIP").hide();
		};
		VTUI.GUID_TIME_OUT = setTimeout(fun,500);
		ClearUserTipAjax();
	});
	
	$("#USER_INFO_TIP").hover(function(){
		clearTimeout(VTUI.GUID_TIME_OUT);
		$("#USER_INFO_TIP").show();
	},function(){
		$("#USER_INFO_TIP").hide();
	});
	
	//标签
	$(".PUB_SHARE_TAG_BOX li").live('click', function(){
		var form = $(this).parents("form");
		var tagInput = $('.PUB_SHARE_TAG',form);
		var tagValue = tagInput.val();
		tagValue = tagValue.replace('　',' ');
		tagValue = tagValue.replace(/ +/g,' ');
		tagValue = ' ' + $.trim(tagValue) + ' ';
		if($(this).hasClass('active'))
		{
			tagValue = tagValue.replace(' ' + $(this).html() + ' ',' ');
			$(this).removeClass('active');
		}
		else
		{
			tagValue += $(this).html();
			$(this).addClass('active');
		}

		tagValue = $.trim(tagValue);
		tagInput.val(tagValue);
	});
	
});

function UserTipShow(obj,html)
{
	$("#USER_INFO_TIP").html(html);
	$("#USER_INFO_TIP").show();
	
	var w = 302;
	var offset = $(obj).offset();
	var left = offset.left;
	var top = offset.top - $("#USER_INFO_TIP").height();
	var width = $(document).width() - 30;
	
	if(left + w > width)
		left = left - w + $(obj).width();
	else if(left < 30)
		left = 30;
	var c = offset.left - left + $(obj).width() / 2 - 8;
	
	$("#USER_INFO_TIP").css({"top":top,"left":left});
	$("#USER_INFO_TIP .tip_arrow").css({"margin-left":c});
}

function GoodsTipShow(obj)
{
	$("#lb_goods").show();
	
	var w = 302;
	var offset = $(obj).offset();
	var left = offset.left;
	var top = offset.top+20;
	var width = $(document).width() - 30;
	
	if(left + w > width)
		left = left - w + $(obj).width();
	else if(left < 30)
		left = 30;
	var c = offset.left - left + $(obj).width() / 2 - 8;
	
	$("#lb_goods").css({"top":top,"left":left});
}

function ClearUserTipAjax()
{
	if(VTUI.User_Tip_Ajax != null)
	{
		VTUI.User_Tip_Ajax.abort();
		VTUI.User_Tip_Ajax = null;
	}
}

function UserTipFollowHandler(obj,result)
{
	var parent = $(obj).parent();
	if(result.data.status == 1)
	{
		parent.html('<span class="fl icrad_add add_ok">已关注</span><a class="follow_del" href="javascript:;" onclick="$.User_Follow_Remove('+ result.data.follow_id +',this,UserTipFollowHandler);">取消</a>');
	}
	else
	{
		parent.html('&nbsp;<a class="green_button" onclick="$.User_Follow('+ result.data.follow_id +',this,UserTipFollowHandler);" href="javascript:;">+加关注</a>');
	}
}
